﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Xinkui.WebModel.BasicControl;
using Xinkui.WebModel.Data;
using Xinkui.DataAccess.AutoGenerator;
using Xinkui.Common;
using Xinkui.WebModel;
using Xinkui.WebModel.Cache;

public partial class UserControl_fore_UC_Search_Company : ForeControl {



    protected int _pageSIze = 8;
    public int PageSIze {
        get {
            return _pageSIze;
        }
        set {
            if (_pageSIze == value)
                return;
            _pageSIze = value;
        }
    }

    public string ProductListURL { get; set; }

    public string CompanyListURL { get; set; }

    public SearchQueryData Query { get; set; }

    protected void Page_Load(object sender, EventArgs e) {
        Query = SearchQueryData.Create();

        if (!string.IsNullOrEmpty(Query.Keyword)) {
            int total = 0;
            var listSource = Singleton<CompanyInfoDataAccess>.Instance.SearchProducts(Query.PageIndex, PageSIze, Query.Keyword, out total);
            this.rptCompanySource.DataSource = listSource;
            this.rptCompanySource.DataBind();
            UC_RewritePager1.FormatUrl = true;
            UC_RewritePager1.CoverNav = false;
            this.UC_RewritePager1.NoteTotal = total;
            this.UC_RewritePager1.JumpUrl = URLHelper.LinkToSearchCompanys(Query.Keyword) + "&p={0}";//"ProductListForImage.aspx?com=1&p={0}";//JumpUrl;
            this.UC_RewritePager1.PageIndex = Query.PageIndex;
            this.UC_RewritePager1.PageSize = PageSIze;
        }
        else {
            this.UC_RewritePager1.Visible = false;
        }
    }


    public string BindingProductProperty(string title, object o) {
        if (o != null && !(o is DBNull) && !string.IsNullOrEmpty(o.ToString())) {
            string v = string.Empty; ;
            if (title.Equals("Business Type")) {
                v = DictCache.GetName((int)DictTypeEnum.BusinessType, (int)o);
            }
            else if (title.Equals("Main Products")) {
                v = o as string;
            }
            else if (title.Equals("Country")) {
                var country = CountryCache.Get((int)o);
                if (country != null) {
                    v = country.Name;
                }
            }
            else {
                v = o.ToString();
            }
            if (!string.IsNullOrEmpty(v)) {
                return string.Format(@" <div class=""para""><strong>{1}:</strong>{0}</div>", v, title);
            }
        }
        return string.Empty;

    }
}